package com.thrd.taiexhibition.ui;

import android.content.Context;
import android.content.res.TypedArray;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.facebook.drawee.generic.RoundingParams;
import com.thrd.taiexhibition.R;
import com.thrd.taiexhibition.fresco.FrescoImage;
import com.thrd.taiexhibition.fresco.FrescoUtils;

/**
 * @author: ${唐杰}
 * @date: 2021/3/18
 */
public class StoryView extends LinearLayout {

    private TextView mTitle;
    private TextView mContent;
    private int orientationType;
    private FrescoImage mFrescoImage;
    private TextView mLabel;
    private TextView mTime;

    public StoryView(Context context) {
        this(context,null);
    }

    public StoryView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs,0);
    }

    public StoryView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.StoryView, defStyleAttr,0);
        orientationType = a.getInt(R.styleable.StoryView_orientation_type,1);
        a.recycle();
        View view=View.inflate(context,orientationType==VERTICAL?R.layout.include_stort_item:R.layout.include_stort_item1,null);
        mTitle = view.findViewById(R.id.tv_title);
        mContent = view.findViewById(R.id.tv_content);
        mFrescoImage = view.findViewById(R.id.fi_image);
        mLabel = view.findViewById(R.id.tv_label);
        mTime = view.findViewById(R.id.tv_time);
        addView(view, LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT);
    }




    public void setTitle(String title){
        if(mTitle!=null){
            mTitle.setText(TextUtils.isEmpty(title)?"":title);
        }
    }

    public void setContent(String content){
        if(mContent!=null){
            mContent.setText(TextUtils.isEmpty(content)?"":content);
        }
    }

    public void setPathImage(String pathImage){
        if(mFrescoImage!=null){
            if(orientationType == HORIZONTAL){
                FrescoUtils.getInstance().setPrefixProgressLoad(getContext(),mFrescoImage,pathImage, RoundingParams.fromCornersRadii(getResources().getDimensionPixelSize(R.dimen.qb_px_4),0,0,getResources().getDimensionPixelSize(R.dimen.qb_px_4)));
            }else {
                FrescoUtils.getInstance().setPrefixProgressLoad(getContext(),mFrescoImage,pathImage, RoundingParams.fromCornersRadii(getResources().getDimensionPixelSize(R.dimen.qb_px_4),getResources().getDimensionPixelSize(R.dimen.qb_px_4),0,0));
            }

        }
    }

    public void setLabel(int label){
        if(mLabel!=null){
            if(label==2){
                mLabel.setText("文章");
                mLabel.setBackgroundResource(R.drawable.story_label_gray_bg);
            }else{
                mLabel.setText("展览");
                mLabel.setBackgroundResource(R.drawable.story_label_bg);
            }

        }
    }

    public void setTime(String time){
        if(mTime!=null){
            mTime.setText(TextUtils.isEmpty(time)?"":time);
        }
    }
}
